﻿///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#pragma once

#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/choice.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/stattext.h>
#include <wx/spinctrl.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/sizer.h>
#include <wx/radiobut.h>
#include <wx/slider.h>
#include <wx/panel.h>
#include <wx/statbmp.h>
#include <wx/frame.h>

#include "WaveformPanel.h"
#include "DeviceModel.h"
#include "utils/serial/SerialPortUtils.h"
#include <boost/algorithm/string.hpp>

class WorkModeBase {
public:
	virtual ~WorkModeBase() = default;
	virtual void EnableUserInterface(bool state) = 0;
	virtual void Entry() {};
	virtual void Exit() {};

protected:

};
///////////////////////////////////////////////////////////////////////////////
/// Class MainForm
///////////////////////////////////////////////////////////////////////////////
class MainForm : public wxFrame, public DeviceDataReceiver, public util::audio::AudioRmsReceiver {
private:
	wxPanel* m_pnlLeft;
	wxChoice* mSelSerialPorts;
	wxStaticText* m_staticText1;
	wxSpinCtrl* m_spinBaudRateConfig;
	wxButton* m_btnOpenSerialPort;
	wxPanel* m_pnlDeviceConfig;
	wxRadioButton* m_modeSwtich;
	wxRadioButton* m_switchON;
	wxRadioButton* m_switchOFF;
	wxRadioButton* m_modeStepless;
	wxSlider* m_slidrSetplessDiming;
	wxStaticText* m_staticText8;
	wxRadioButton* m_modeSawtooth;
	wxSlider* m_slidrSawInterval;
	wxStaticText* m_staticText9;
	wxRadioButton* m_modeTriangle;
	wxSlider* m_slidrTrianInterval;
	wxStaticText* m_staticText10;
	wxRadioButton* m_modeSinWave;
	wxSlider* m_slidrSinInterval;
	wxStaticText* m_staticText11;
	wxRadioButton* m_modeAudioWave;
	wxStaticText* m_staticText12;
	wxStaticText* m_lblModeStatus;
	wxPanel* m_pnlRight;
	WaveformPanel* m_pnlShowWave;
	wxPanel* m_pnlQrCode;
	wxStaticBitmap* m_bmpBiliBili;

	// Virtual event handlers, override them in your derived class
	virtual void OnClickSerialPortOpenOrClose(wxCommandEvent& event);
	virtual void OnModeSelect4Switch(wxCommandEvent& event);
	virtual void OnModeSelect4Stepless(wxCommandEvent& event);
	virtual void OnModeSelect4Sawtooth(wxCommandEvent& event);
	virtual void OnModeSelect4Triangle(wxCommandEvent& event);
	virtual void OnModeSelect4SinWave(wxCommandEvent& event);
	virtual void OnModeSelect4AudioWave(wxCommandEvent& event);
	virtual void OnSwitchLedON(wxCommandEvent& event);
	virtual void OnSwitchLedOFF(wxCommandEvent& event);
	virtual void OnSteplessChanging(wxCommandEvent& event);
	virtual void OnSawIntervalChanging(wxScrollEvent& event);
	virtual void OnTriangleIntervalChanging(wxScrollEvent& event);
	virtual void OnSinIntervalChanging(wxScrollEvent& event);

public:

	MainForm(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(750, 462), long style = wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);

	~MainForm();

	void WaveformPostNewData(double x, double y, int tag = 0);

protected:
	enum class WorkMode {
		Disable = 0,
		Switch,
		Stepless,
		Sawtooth,
		Triangle,
		SinWave,
		AudioWave
	};
	WorkMode curWorkMode = WorkMode::Disable;

	void InitWorkMode();

	void ChangeWorkMode(WorkMode newMode);

	void LeaveWorkMode(WorkMode workMode);

	void EnterWorkMode(WorkMode workMode);

	void EnableWorkModeUserInterface(WorkMode workMode, bool state);

	void ResetWorkModeUserInterface(WorkMode workMode);

	bool EnableWorkMode4TartetDevice(WorkMode workMode);

	wxString GetWorkModeName(WorkMode workMode) const;

	WorkMode GetCurWorkMode() const {
		return curWorkMode;
	}

	void ClearWaveform() {
		if (m_pnlShowWave) {
			m_pnlShowWave->AsyncClearData();
		}
	}

	void OnReportLedStatus(double time, double lighteness) override;
	void OnReceiveRMS(int tag, double time, double rms) override;

private:
	std::vector<util::ser::SerialPortInfo> curComPorts;
	std::unique_ptr<DeviceModel> targetDevice;
};

